/**
 * 贪心算法-柠檬水找零-力扣860
 */

public class Practice_1 {
    public static void main(String[] args) {
        int[] bills = {5, 5, 10, 10, 20};
        boolean result = lemonadeChange(bills);
        System.out.println(result);
    }
    public static boolean lemonadeChange(int[] bills) {
        int five = 0;
        int ten = 0;
        int twen = 0;
        for (int i = 0; i < bills.length; i++) {
            if (bills[i] == 5) {
                five++;
            }
            if (bills[i] == 10) {
                five--;
                ten++;
                if (five < 0) {
                    return false;
                }
            }
            if (bills[i] == 20) {
                twen++;
                int tmp = bills[i] - 5;
                if (ten >= 1 && five >= 1) {
                    ten--;
                    five--;
                } else if (ten < 1 && five >= 3) {
                    five = five - 3;
                } else {
                    return false;
                }
            }

        }
        return true;

    }
}
